package com.dq.controller.user;

import com.alibaba.fastjson.JSONObject;
import com.dq.controller.in.RechargeCardRequest;
import com.dq.controller.in.UserAccountStaffUserRequest;
import com.dq.controller.in.UserCardQuery;
import com.dq.domain.sys.user.user.centre.UserCard;
import com.dq.domain.sys.user.user.centre.UserCardServiceProjectCentre;
import com.dq.exception.customException.AdminException;
import com.dq.service.AllService;
import com.dq.vo.ListDataVo;
import com.dq.vo.Vo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author luchangtong
 * @Date 2020/4/14 13:51
 */
@RestController
@RequestMapping("/sys/userCard/")
@Api(description = "会员卡管理")
public class SysUserCardController extends AllService {

    @ApiOperation("会员卡添加")
    @PostMapping("add")
    public Vo add (@RequestBody RechargeCardRequest rechargeCardRequest) throws AdminException{
        return userCardService.addCard(rechargeCardRequest);
    }

    @ApiOperation("会员卡编辑")
    @PostMapping("edit")
    public Vo edit (@RequestBody RechargeCardRequest rechargeCardRequest) throws AdminException{
        return userCardService.editCard(rechargeCardRequest);
    }

    @ApiOperation("会员卡编辑状态")
    @PostMapping("editStatus/{id}")
    public Vo editStatus (@PathVariable Long id) throws AdminException{
        return userCardService.editStatus(id);
    }
    @ApiOperation("会员卡列表")
    @PostMapping("list")
    public Vo list (@RequestBody UserCardQuery userCardQuery) throws AdminException{

        List<UserCard> list = userCardService.cardList(userCardQuery);

        List<UserCard.Vo> toList = userCardService.transformUserCard(list);

        return new ListDataVo(toList,userCardService.cardCount(userCardQuery));
    }

    @ApiOperation("充卡")
    @PostMapping("distributionRatio")
    public Vo distributionRatio(@RequestBody UserAccountStaffUserRequest userAccountStaffUserRequest) throws AdminException{

        return userAccountStaffUserService.distributionRatio(userAccountStaffUserRequest);
    }

    @ApiOperation("根据用户id查看用户所有会员卡 不分页")
    @GetMapping("cardByUser/{wxUserId}")
    public Vo cardByUser(@PathVariable Long wxUserId) throws AdminException{
        List<UserCard> list = userCardService.cardByUser(wxUserId);
        List<UserCard.Vo> toList = userCardService.transformUserCard(list);
        return new Vo(toList);
    }

}
